from urllib.request import Request,urlopen
from urllib.parse import urlencode
import time

# class Spider(object):
#     def __int__(self):
#         self.ur1 = "https://movie.douban.com/j/chart/top_list?type=11&interval_id=100%3A90&action=&start={}&limit=20"

def get_html(ur1):
    req = Request(ur1,headers={
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"
        })
    resp = urlopen(req)
    html = resp.read().decode('utf-8')
    return html
def save_html(filmname,html):
    with open(filmname,'w',encoding='utf-8')as f:
        f.write(html)

def run():
    for i in range(5):
        ur1 ="https://movie.douban.com/j/chart/top_list?type=11&interval_id=100%3A90&action=&start={}&limit=20".format(i*20)
        html = get_html(ur1)
        filename = "第"+str(i+1)+'页.txt'
        save_html(filename,html)
        time.sleep(3)

if __name__=="__main__":
    run()

